package com.example.myapplication;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.example.myapplication.lunbo.LooperPageAdapter;

import java.util.ArrayList;
import java.util.List;

public class Index extends AppCompatActivity {
    private Context mContext;
    private GridView mGridView;
    private BaseAdapter mAdapter=null;
    private ArrayList<Iocn> mData=null;
    private ViewPager mLoopPager;
    private LooperPageAdapter mLooperPageAdapter;
    private List<Integer> sPics=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mContext=Index.this;
        mGridView=(GridView)findViewById(R.id.gridview);
    mData=new ArrayList<>();
        mData.add(new Iocn(R.drawable.phone,"手机"));
        mData.add(new Iocn(R.drawable.book,"笔记本"));
        mData.add(new Iocn(R.drawable.ping,"平板"));
        mData.add(new Iocn(R.drawable.watch,"智能手表"));
        mData.add(new Iocn(R.drawable.peper,"居家百货"));
        mData.add(new Iocn(R.drawable.richang,"生活日常"));
        mData.add(new Iocn(R.drawable.quan,"大额好券"));
        mData.add(new Iocn(R.drawable.all,"全部分类"));

    mAdapter=new MyAdapter<Iocn>(mData,R.layout.gridview_item){
        @Override
        public void bindView(ViewHolder holder,Iocn obj){
            holder.setImageResource(R.id.img,obj.getiID());
            holder.setText(R.id.text,obj.getiName());
        }
    };
        mGridView.setAdapter(mAdapter);
        mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(mContext,"你点击了~"+position+"~项",Toast.LENGTH_SHORT).show();
        }
    });
//        GridView gridview = (GridView) findViewById(R.id.gridview);
//        ArrayList<HashMap<String, Object>> meumList = new ArrayList<HashMap<String, Object>>();
//        for (int i=1;i<9;i++){
//            HashMap<String,Object> map=new HashMap<>();
//            map.put("ItemImage",R.drawable.phone);
//            map.put("ItemText",""+i);
//            meumList.add(map);
//        }
//        SimpleAdapter simpleAdapter=new SimpleAdapter(this,
//                meumList,
//                R.layout.gridview_item,
//                new String[]{"ItemImage","ItemText"},
//                new int[]{R.id.img,R.id.text}
//                );
//        gridview.setAdapter(simpleAdapter);
//    }
        sPics.add(R.drawable.banner);
        sPics.add(R.drawable.banner);
        sPics.add(R.drawable.banner);
    initData();
}
    private void initData(){
        //第一步，就是找这个viewPager控件
        mLoopPager=(ViewPager)this.findViewById(R.id.looper_paper);
        //设置适配器
        mLooperPageAdapter=new LooperPageAdapter();
        mLooperPageAdapter.setData(sPics);
        mLoopPager.setAdapter(mLooperPageAdapter);
    }
}
